<?php require_once(dirname(__FILE__) . '/inc/config.inc.php');
IsModelPriv('order'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>用户列表</title>
    <link href="templates/style/admin.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="templates/js/jquery.min.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="ui/css/bootstrap.min.css">
    <link rel="stylesheet" href="ui/css/bootstrap-theme.min.css">
    <!-- 最新版本的 layui 核心 CSS 文件 -->

    <link href="layui/css/layui.css" rel="stylesheet" type="text/css" media="all"/>
    <script src="layui/layui.all.js"></script>
    <script type="text/javascript">

    </script>
</head>
<body>
<style>
    .layui-table-cell { /*最后的pic为字段的field*/
        height: 100%;
        max-width: 100%;
        height: auto;
        white-space: normal;
        word-wrap: break-word;
        word-break: break-all;
    }

    .layui-form-label { width: 100px;}

    .mt10 { margin-top: 10px;}

    body { overflow: auto !important;}

    .layui-tab-card > .layui-tab-title .layui-this {
        background-color: #009688;
        color: #fff;
    }

    .ss .layui-input-block .layui-input {
        width: 212px !important;
    }

    .layui-card-header span {
        margin-left: 18px;
    }

</style>
<div>
    <div class="">
        <div class="layui-fluid">
            <div class="layui-row">
                <!-- 右表 -->
                <div class="layui-col-sm12 mt10"></div>
                <div class="layui-card layadmin-header">
                    <div class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
                        <a lay-href="">主页</a><span lay-separator="">/</span>
                        <a><cite>工程列表</cite></a><span lay-separator="">/</span>

                    </div>
                </div>
                <div class="layui-col-sm12">

                    <div class="layui-col-sm12 " style="margin-top: 10px;">
                        <div class=" layuiadmin-card-header-auto">
                            <div class="layui-form  layuiadmin-card-header-auto" lay-filter="layadmin-userfront-formlist">
                                <div class="layui-form-item ss">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">项目名称 ≈</label>
                                        <div class="layui-input-block">
                                            <input type="text" class="layui-input" name="projectname" id="projectname" autocomplete="off" value="">
                                        </div>
                                    </div>
                                    <div class="layui-inline"><label class="layui-form-label">项目经理</label>
                                        <div class="layui-input-block">
                                            <select name="pmid" id="pmid" lay-filter="pmid">
                                                <option value="0">所有</option>
                                                <?php
                                                $dosql->Execute("SELECT * FROM `#@__user` WHERE ispm=1 order by id ASC", 10);
                                                while ($row = $dosql->GetArray(10)) {
                                                    echo '<option value="' . $row['id'] . '" >' . $row['truename'] . '</option>';

                                                }
                                                ?>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">工程师</label>
                                        <div class="layui-input-block">
                                            <select name="manageid" id="manageid" lay-filter="pmid">
                                                <option value="0">所有</option>
                                                <?php
                                                $dosql->Execute("SELECT * FROM `#@__user` WHERE `level`=3 order by id ASC", 10);
                                                while ($row = $dosql->GetArray(10)) {
                                                    echo '<option value="' . $row['id'] . '" >' . $row['truename'] . '</option>';

                                                }
                                                ?>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label" lay-tip="添加时间">开始时间</label>
                                        <div class="layui-input-block">
                                            <input type="text" class="layui-input" name="dtime" id="test-laydate-format-range2"
                                                   placeholder="开始 到 结束" autocomplete="off" value="">
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <button class="layui-btn layuiadmin-btn-useradmin" lay-submit="" lay-filter="LAY-user-front-search" lay-tips="点击进行搜索">
                                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i></button>
                                    </div>
                                    <div class="layui-inline">
                                        <button class="layui-btn  layuiadmin-btn-useradmin layui-btn-danger" data-type="refush" lay-tips="重置搜索条件，并显示全部的用户">
                                            重置搜索
                                        </button>
                                    </div>
                                    <div class="layui-inline">
                                        <button class="layui-btn  layuiadmin-btn-useradmin layui-btn-warm" data-type="add" lay-tips="添加新的工程">
                                            添加新工程
                                        </button>
                                    </div>

                                </div>
                            </div>


                        </div>
                    </div>
                    <div class="layui-card">
                        <div class="layui-col-sm12 ">
                            <div class="layui-tab layui-tab-card">
                                <ul class="layui-tab-title">
                                    <li class="layui-this" value="-1" lay-tips="所有状态的工单">全部工程</li>
                                    <li value="0" lay-tips="添加后，管理员中止">中止工程</li>
                                    <li value="3" lay-tips="管理员发起，但是项目经理没有接单">待接单</li>
                                    <li value="4">施工中</li>
                                    <li value="5">工程竣工</li>
                                    <li value="6">验收中</li>
                                    <li value="7">通过验收</li>
                                </ul>
                                <div class="layui-tab-content">
                                    <table id="projectlist" lay-filter="projectlist"></table>
                                    <script type="text/html" id="table_status1">
                                        {{#  if(d.jindu==0){ }}
                                        <button class="layui-btn layui-btn-primary layui-btn-xs">已中止</button>
                                        {{#  }else{ }}
                                        {{#  if(d.over_time>0){ }}
                                        {{#  if(d.jindu==5){ }}
                                        <button class="layui-btn layui-btn-success layui-btn-xs">已竣工待验收</button>

                                        {{#  } }}
                                        {{#  if(d.jindu==6){ }}
                                        <button class="layui-btn layui-btn-success layui-btn-xs">验收中</button>
                                        {{#  } }}

                                        {{#  if(d.jindu==7){ }}
                                        <button class="layui-btn layui-btn-success layui-btn-xs">验收通过</button>
                                        {{#  } }}


                                        {{#  } }}

                                        {{#  if(d.over_time ==0){ }}
                                            {{#  if(d.jindu==3){ }}
                                            <button class="layui-btn layui-btn-success layui-btn-xs">等待项目经理接单</button>
                                             {{#  }else{ }}
                                             <button class="layui-btn layui-btn-danger layui-btn-xs">施工中</button>
                                            {{#  } }}

                                            {{#  if(d.signIn ==0 && d.jindu==4 ){ }}
                                            <button class="layui-btn layui-btn-danger layui-btn-xs">施工签退</button>
                                            {{#  }  }}
                                            {{#  if(d.signIn ==1  && d.jindu==4 ){ }}
                                            <button class="layui-btn  layui-btn-xs">施工签到</button>
                                            {{#  }  }}
                                        {{#  } } }}
                                    </script>
                                    <script type="text/html" id="table-list-op1">
                                        <a class="layui-btn layui-btn-success layui-btn-xs" lay-event="detail">
                                            <i class="layui-icon layui-icon-set"></i>详情
                                        </a>
                                        <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">
                                            <i class="layui-icon layui-icon-edit"></i>编辑
                                        </a>
                                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">
                                            <i class="layui-icon layui-icon-delete"></i>删除
                                        </a>
                                        {{#  if(d.jindu==5){ }}
                                        <button class="layui-btn  layui-btn-xs" lay-event="success">
                                            <i class="layui-icon layui-icon-ok"></i>验收通过
                                        </button>{{#} }}
                                    </script>

                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="">
        layui.config({
            base: 'layui/lay/modules/'
        }).extend({
            admin: 'admin',
            view: 'view'
        }).use(['table', 'admin', 'view', 'laydate'], function () {

            //无需再执行layui.use()方法加载模块，直接使用即可
            var form = layui.form,
                layer = layui.layer,
                admin = layui.admin,
                view = layui.view,
                laydate = layui.laydate,
                table = layui.table;
            //第一个实例
            table.render({
                elem: '#projectlist'
                , url: 'json/project/list.php' //数据接口
                , page: true //开启分页
                , cellMinWidth: 100
                , where: {status: -1}
                , cols:
                    [[ //表头
                        {field: 'id', title: 'ID', width: 80}
                        , {field: 'typename', align: 'center', title: '类型'}
                        , {field: 'projectname', align: 'center', title: '项目名称'}
                        , {field: 'pm', align: 'center', title: '项目经理'}
                        , {field: 'school', align: 'center', title: '甲方'}
                        , {field: 'truename', align: 'center', title: '甲方联系人'}
                        , {field: 'address', align: 'center', title: '施工地址'}
                        , {field: 'times', align: 'center', title: '项目周期'}
                        , {field: 'addtime', align: 'center', title: '添加时间'}
                        , {field: 'status', title: '项目状态', toolbar: '#table_status1'}
                        , {field: 'op', title: '操作', toolbar: '#table-list-op1', width: 230}
                    ]],
                limit: 8,
                limits: [10, 15, 20, 25, 30],
                text: {none: '暂无数据'}
            });


            $(".layui-tab-title li").click(function () {
                var status = this.value;
                console.log(status);
                table.render({
                    elem: '#projectlist'
                    , url: 'json/project/list.php' //数据接口
                    , page: true //开启分页
                    , cellMinWidth: 100
                    , where: {status: status}
                    , cols:
                        [[ //表头
                            {field: 'id', title: 'ID', width: 80}
                            , {field: 'typename', align: 'center', title: '类型'}
                            , {field: 'projectname', align: 'center', title: '项目名称'}
                            , {field: 'pm', align: 'center', title: '项目经理'}
                            , {field: 'school', align: 'center', title: '甲方'}
                            , {field: 'truename', align: 'center', title: '甲方联系人'}
                            , {field: 'address', align: 'center', title: '施工地址'}
                            , {field: 'times', align: 'center', title: '项目周期'}
                            , {field: 'addtime', align: 'center', title: '添加时间'}
                            , {field: 'status', title: '项目状态', toolbar: '#table_status1'}
                            , {field: 'op', title: '操作', toolbar: '#table-list-op1', width: 230}
                        ]],
                    limit: 8,
                    limits: [10, 15, 20, 25, 30],
                    text: {none: '暂无数据'}
                });
            });

            form.render(null, 'layadmin-userfront-formlist');


            //监听搜索
            form.on('submit(LAY-user-front-search)', function (data) {
                field = data.field;            //执行重载
                table.reload('projectlist', {
                    where: field,
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            });


            //事件
            var active = {
                refush: function () {
                    $("#projectname").val("");
                    $("#test-laydate-format-range2").val("");
                    $("#pmid").get(0).selectedIndex = 0;
                    $("#manageid").get(0).selectedIndex = 0;
                    form.render(null, 'layadmin-userfront-formlist');
                    table.reload('projectlist', {
                        where: {
                            'projectname': '',
                            'dtime': '',
                            'pmid': 0,
                            'manageid': 0
                        },
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    });
                },
                add: function () {
                    layer.open({
                        type: 2,
                        skin: 'layui-layer-molv', //样式类名
                        title: '添加新工程',
                        shadeClose: true,
                        shade: false,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['893px', '600px'],
                        content: ['project_add.php'], //iframe的url，no代表不显示滚动条
                        end: function () {
                            table.reload('projectlist'); //重载表格
                        }
                    });
                },

            };
            $('.layui-btn.layuiadmin-btn-useradmin').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });


            //监听工具条
            table.on('tool(projectlist)', function (obj) {
                var data = obj.data;
                console.log(data)
                if (obj.event === 'edit') {
                    console.log(data);
                    layer.open({
                        type: 2,
                        skin: 'layui-layer-lan', //样式类名
                        title: '编辑工程信息',
                        shadeClose: true,
                        shade: false,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['893px', '600px'],
                        content: 'project_edit.php?id=' + data.id,
                        end: function () {
                            table.reload('projectlist'); //重载表格
                        }
                    });
                } else if (obj.event === 'del') {

                    layer.confirm('确定删除  [' + data.projectname + ']  记录？', function (index) {
                        $.ajax({
                            url: "json/project/project_do.php",
                            data: {
                                "field": [],
                                "id": data.id,
                                'action': 'del'
                            },
                            type: "POST",
                            success: function () {
                                layer.close(index); //关闭弹层

                                //登入成功的提示与跳转
                                layer.msg('删除成功', {offset: '15px', icon: 1, time: 1000}, function () {
                                    table.reload('projectlist'); //数据刷新
                                });


                            }
                        });
                    });
                } else if (obj.event == "detail") {
                    var data = obj.data;
                    console.log(data);
                    layer.open({
                        type: 2,
                        skin: 'layui-layer-lan', //样式类名
                        title: '工程详情',
                        shadeClose: true,
                        shade: false,
                        maxmin: true, //开启最大化最小化按钮
                        area: ['830px', '690px'],
                        content: 'projectDetail.php?id=' + data.id,

                    });

                } else if (obj.event == "success") {
                    var data = obj.data;
                    console.log(data);
                    layer.confirm('确定工程  [' + data.projectname + ']  验证通过？', function (index) {
                        $.ajax({
                            url: "json/project/project_do.php",
                            data: {
                                "field": [],
                                "id": data.id,
                                'action': 'success'
                            },
                            type: "POST",
                            success: function () {
                                layer.close(index); //关闭弹层

                                //登入成功的提示与跳转
                                layer.msg('操作成功', {offset: '15px', icon: 1, time: 1000}, function () {
                                    table.reload('projectlist'); //数据刷新
                                });


                            }
                        });
                    });

                }
            });

            //获取当前时间
            var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var day = date.getDate();
            if (month < 10) {
                month = "0" + month;
            }
            if (day < 10) {
                day = "0" + day;
            }
            var nowDate = year + "-" + month + "-" + day;
            //日期时间范围
            laydate.render({
                elem: '#test-laydate-format-range2'
                , range: '~'
                , max: nowDate
            });

        });
    </script>

</body>
</html>